#ifndef __RENDERSYSTEMCAPABILITIESMANAGER_H__
#define __RENDERSYSTEMCAPABILITIESMANAGER_H__

#include "U2PreRequest.h"
#include "U2MemoryAllocatorConfig.h"
#include "U2Singleton.h"
#include "U2RenderSystemCapabilities.h"



U2EG_NAMESPACE_BEGIN


class U2RenderSystemCapabilitiesSerializer;


/** Class for managing U2RenderSystemCapabilities database for Ogre.
    @remarks This class behaves similarly to other ResourceManager, although .rendercaps are not resources.
			It contains and abstract a .rendercaps Serializer
*/
class _U2Share U2RenderSystemCapabilitiesManager :  public U2Singleton<U2RenderSystemCapabilitiesManager>, public RenderSysAlloc
{

public:

    /** Default constructor.
    */
    U2RenderSystemCapabilitiesManager();

    /** Default destructor.
    */
    virtual ~U2RenderSystemCapabilitiesManager();


    /** @see ScriptLoader::parseScript
    */
    void parseCapabilitiesFromArchive(const U2String& filename, const U2String& archiveType, bool recursive = true);
	
	/** Returns a capability loaded with RenderSystemCapabilitiesManager::parseCapabilitiesFromArchive method
	* @return NULL if the name is invalid, a parsed U2RenderSystemCapabilities otherwise.
	*/
    U2RenderSystemCapabilities* loadParsedCapabilities(const U2String& name);

	/** Access to the internal std::map of loaded capabilities */
	const std::map<U2String, U2RenderSystemCapabilities*> &getCapabilities() const;

    /** Method used by RenderSystemCapabilitiesSerializer::parseScript */
    void _addRenderSystemCapabilities(const U2String& name, U2RenderSystemCapabilities* caps);

    /** Override standard U2Singleton retrieval.
    @remarks
    Why do we do this? Well, it's because the U2Singleton
    implementation is in a .h file, which means it gets compiled
    into anybody who includes it. This is needed for the
    U2Singleton template to work, but we actually only want it
    compiled into the implementation of the class based on the
    U2Singleton, not all of them. If we don't change this, we get
    link errors when trying to use the U2Singleton-based class from
    an outside dll.
    @par
    This method just delegates to the template version anyway,
    but the implementation stays in this single compilation unit,
    preventing link errors.
    */
    static U2RenderSystemCapabilitiesManager& getSingleton(void);
    /** Override standard U2Singleton retrieval.
    @remarks
    Why do we do this? Well, it's because the U2Singleton
    implementation is in a .h file, which means it gets compiled
    into anybody who includes it. This is needed for the
    U2Singleton template to work, but we actually only want it
    compiled into the implementation of the class based on the
    U2Singleton, not all of them. If we don't change this, we get
    link errors when trying to use the U2Singleton-based class from
    an outside dll.
    @par
    This method just delegates to the template version anyway,
    but the implementation stays in this single compilation unit,
    preventing link errors.
    */
    static U2RenderSystemCapabilitiesManager* getSingletonPtr(void);

protected:

    U2RenderSystemCapabilitiesSerializer* mSerializer;

    typedef std::map<U2String, U2RenderSystemCapabilities*> CapabilitiesMap;
    CapabilitiesMap mCapabilitiesMap;

    const U2String mScriptPattern;

};


U2EG_NAMESPACE_END

#endif
